import java.io.StringReader;
import java.security.NoSuchAlgorithmException;

import javax.xml.bind.JAXBException;

import junit.framework.TestCase;

import org.junit.Test;
import org.xml.sax.SAXException;

import com.columboid.protocol.syncml.helper.JaxbHelper;
import com.columboid.protocol.syncml.representation.ObjectFactory;
import com.columboid.protocol.syncml.representation.SyncML;
import com.columboid.protocol.syncml.tests.resources.LoginString;
import com.columboid.web.helper.RequestHelper;

public class RequestHelperTest extends TestCase {

	@Test
	public void testRequestWithCredData() throws Exception {
		String requestString = LoginString.getFirstLoginRequest();
		String xsd = JaxbHelper.getSyncMLSchema();

		StringReader xmlReader = new StringReader(requestString);
		StringReader xsdReader = new StringReader(xsd);
		SyncML requestSml = null;

		requestSml = JaxbHelper.CreateSyncMLObject(xmlReader, xsdReader,SyncML.class,ObjectFactory.class);
		xmlReader.close();
		xsdReader.close();
		String response = null;

		response = RequestHelper.getStringFromSyncMLObject(requestSml);

		assertFalse(response.equals(""));
	}

	@Test
	public void testRequestWithoutCredData() throws Exception {
		String requestString = LoginString.getSecondLoginRequest("Challenge");
		String xsd = JaxbHelper.getSyncMLSchema();

		StringReader xmlReader = new StringReader(requestString);
		StringReader xsdReader = new StringReader(xsd);
		SyncML requestSml = JaxbHelper.CreateSyncMLObject(xmlReader, xsdReader,SyncML.class,ObjectFactory.class);
		xmlReader.close();
		xsdReader.close();

		String response = RequestHelper.getStringFromSyncMLObject(requestSml);
		assertFalse(response.equals(""));
	}

}
